define(function (require,exports,module) {

    var angular = require('angular');

    angular.module('directives.page',[])
        .directive('pagination',[
            function () {
                return {
                    restrict: "A",
                    scope: {ngModel: '='},
                    require:'^ngModel',
                    replace:true,
                    template: [
                        '<div class="tool_area" ng-show="ngModel.pages > 1">',
                            '<div class="pagination_wrp pageNavigator">',
                                '<div class="pageination">',
                                    '<span class="page_nav_area">',
                                        '<a href="javascript:;" class="btn page_prev {{ngModel.current == 1 ? \'disabled\' : \'\'}}" ng-click="change(+ngModel.current - 1)">',
                                            '<i class="arrow"></i>',
                                        '</a>',
                                        ' <span class="page_num">',
                                            '<label>{{ngModel.current}}</label>',
                                            '<span class="num_gap">/</span>',
                                            '<label>{{ngModel.pages}}</label>',
                                        '</span>',
                                        ' <a href="javascript:;" class="btn page_next {{ngModel.current == ngModel.pages ? \'disabled\' : \'\'}}" ng-click="change(+ngModel.current + 1)">',
                                            '<i class="arrow"></i>',
                                        '</a>',
                                    '</span>',
                                    '<span class="goto_area">',
                                        '<input type="text" ng-model="ngModel.page">',
                                        '<a href="javascript:;" ng-click="change(ngModel.page)" class="btn page_go">跳转</a>',
                                    '</span>',
                                '</div>',
                            '</div>',
                        '</div>'
                    ].join(''),
                    controller: [
                        '$scope',
                        function ($scope) {
                            $scope.change = function (page) {
                                if (page && Math.abs(page) === Math.ceil(page) && page <= $scope.ngModel.pages) {
                                    $scope.ngModel.current = page;
                                    $scope.ngModel.change(page);
                                }
                            };
                        }
                    ],
                    link: function (scope,element,attr) {
                    }
                };
            }
        ]);
});
